#Maintainer: Ma, Leon <akml@163.com>

_realname=global
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=6.6.7
pkgrel=2
pkgdesc="GNU GLOBAL source code tagging system (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clang32')
url='https://www.gnu.org/software/global'
license=('GPL3')
depends=("${MINGW_PACKAGE_PREFIX}-libwinpthread-git")
makedepends=(
  "${MINGW_PACKAGE_PREFIX}-cc"
  "${MINGW_PACKAGE_PREFIX}-ncurses"
  "${MINGW_PACKAGE_PREFIX}-autotools"
  "${MINGW_PACKAGE_PREFIX}-gperf"
)
source=("https://ftp.gnu.org/gnu/${_realname}/${_realname}-${pkgver}.tar.gz"{,.sig}
        '001-global-6.6.2-mingw64.patch')
sha256sums=('69a0f77f53827c5568176c1d382166df361e74263a047f0b3058aa2f2ad58a3c'
            'SKIP'
            '5a4ea7a804ee5c874e4297047bc5e22aaa0b422b4b50659d90b147f2b920c7fa')
validpgpkeys=('26F631B43D624A927E6F1C33969C3BE389DDA6EB') # Shigio YAMAGUCHI <shigio@gnu.org>

_global_srcdir=${_realname}-${pkgver}

prepare() {
  cd ${_global_srcdir}

  patch -p1 -i ${srcdir}/001-global-6.6.2-mingw64.patch
  autoconf
}

build() {
  [[ -d "${srcdir}"/build-${MSYSTEM} ]] && rm -rf "${srcdir}"/build-${MSYSTEM}
  mkdir -p "${srcdir}"/build-${MSYSTEM} && cd "${srcdir}"/build-${MSYSTEM}

  export CPPFLAGS="-I${MINGW_PREFIX}/include/ncurses"

  ../${_global_srcdir}/configure \
    --prefix=${MINGW_PREFIX} \
    --build=${MINGW_CHOST} \
    --host=${MINGW_CHOST} \
    --target=${MINGW_CHOST} \
    --with-ncurses=${MINGW_PREFIX}

  make
}

check() {
  cd "${srcdir}"/build-${MSYSTEM}
  make check
}

package() {
  cd "${srcdir}"/build-${MSYSTEM}
  make install DESTDIR="${pkgdir}"
}
